#include "MSqlDatabase.h"
#include "MSqlServer.h"
#include "MSqlConnectionPool.h"

using namespace NsMSql;

NsMSql::MSqlDatabase::MSqlDatabase(const MSqlServerAttr& sqlServerAttr)
{
	m_sqlServerAttr = sqlServerAttr;
	//初始化连接池
	m_pSqlConnectionPool = new MSqlConnectionPool(this);		
}

NsMSql::MSqlDatabase::~MSqlDatabase()
{
}

bool NsMSql::MSqlDatabase::drop()
{
	return false;
}

bool NsMSql::MSqlDatabase::createTable(const QString& tableName, const QList<MTableField>& tableFields)
{
	MSqlTable* pSqlTable = new MSqlTable(this, tableName, tableFields);
	bool res = pSqlTable->create();
	if (res)
		m_nameToSqlTableMap[tableName] = pSqlTable;
	return res;
}

bool NsMSql::MSqlDatabase::dropTable(const QString& tableName)
{
	bool res = false;
	if (m_nameToSqlTableMap.contains(tableName))
		res = m_nameToSqlTableMap[tableName]->drop();
	return res;
}

MSqlServerAttr NsMSql::MSqlDatabase::getSqlServerAttr()
{
	return m_sqlServerAttr;
}

MSqlConnectionPool* NsMSql::MSqlDatabase::getSqlConnectionPool()
{
	return m_pSqlConnectionPool;
}
